package com.daocao.user.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.daocao.common.constants.HttpStatus;
import com.daocao.common.entity.UmsSysUser;
import com.daocao.common.mapper.UmsSysUserMapper;
import com.daocao.common.utils.DaoCaoSecurityUtil;
import com.daocao.user.entity.vo.UserInfoVO;
import com.daocao.user.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.daocao.common.exception.ServiceException;


@Service
@Slf4j
public class SysUserServiceImpl implements SysUserService {

    private final UmsSysUserMapper sysUserMapper;

    public SysUserServiceImpl(UmsSysUserMapper sysUserMapper) {
        this.sysUserMapper = sysUserMapper;
    }

    @Override
    public UserInfoVO searchUserInfo() {
        Long userId = DaoCaoSecurityUtil.getUserId();
        UmsSysUser umsSysUser = sysUserMapper.selectById(userId);
        if (ObjectUtil.isNull(umsSysUser)) {
            throw new ServiceException(HttpStatus.FORBIDDEN, "");
        }
        UserInfoVO userInfoVO = new UserInfoVO();
        BeanUtil.copyProperties(umsSysUser, userInfoVO);
        log.info("获取用户信息 === > {}", userInfoVO);
        return userInfoVO;
    }
}
